<template>
	<view class="content">
		<view class="padding_lrb" style="margin-bottom: 200rpx;">
			<view class="zwtimg placeholderimg flexcenter" style="margin-top: 300rpx;" v-if="addressList.length==0">
							<image src="@/static/image/bg-icons/placeholderimg.png" mode=""></image>
						</view>
			<view class="ffffff border  padding  margin_top" v-for="item in addressList" :key="item.id" @click="checkaddress(item.id)">
				<view class="flexleft text_w color_ling">
					<view class=" margin_right1">{{item.name}}</view>
					<view>{{item.mobile}}</view>
				</view>
				<view class="flexleft xiahuaxian margin_top">
					<view class="address margin_right1"></view>
					<view class="text_e color_san">{{item.cityinfo}}/{{item.address_detail}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="flexleft" @click.stop="selectmr(item)">
						<!-- 已勾选 -->
						<view class="xuanzhong margin_right1" v-if="item.status==1"></view>
						<!-- 未勾选 -->
						<view class="wiexuanzhong margin_right1" v-if="item.status==0"></view>
						<view class="text_f color_san">设为默认</view>
					</view>
					<view class="flexright">
						<view class="flexleft margin_right3" @click.stop="editAddress(item.id)">
							<view class="bianji margin_right1"></view>
							<view class="text_f color_san">编辑</view>
						</view>
						<view class="flexleft" @click.stop="shanchu(item.id)">
							<view class="del  margin_right1"></view>
							<view class="text_f color_san">删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="footer_di" @click="dizhi">
			<view class="footer_btn">+新增收货地址</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type:0,
				addressList: [],
			}
		},
		onLoad(options) {
			if(options.type){
				this.type = options.type
			}
		},
		onShow() {
			this.getAddressList()
		},
		methods: {
			checkaddress(id){
				if(this.type==1){
					uni.$emit("checkAddressId",id)
					uni.navigateBack(1)
				}
			},
			// 设置默认地址
			selectmr(item) {
				if (item.status == 1) {
					return false
				}
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				httpRequest.request('/api/user/setAddressMr', 'GET', {
					id: item.id,
					status: item.status == 0 ? 1 : 0,
				}, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						this.getAddressList()
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			editAddress(id) { //编辑收货地址
				uni.navigateTo({
					url: "/pages_index/xinzengdz?id=" + id
				})
			},
			// 删除地址
			shanchu(id) {
				httpRequest.modal('提示', '确认删除当前数据吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/user/deladdress', 'GET', {
							id: id
						}, false, false, true).then(res => {
							if (res.code == 1) {
								httpRequest.toast(res.msg)
								this.getAddressList()
							} else {
								httpRequest.toast(res.msg)
							}
						})
					}
				})
			},
			getAddressList() { //地址列表
				httpRequest.request('/api/user/addressList', 'GET', {}).then(res => {
					if (res.code == 1) {
						console.log(res.data)
						this.addressList = res.data
					}
				})
			},
			dizhi() {
				uni.navigateTo({
					url: "/pages_index/xinzengdz"
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content {

		overflow: hidden;
	}

	.xiahuaxian {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.footer_btn {
		font-size: 32rpx;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		padding: 20rpx 20rpx;
		background-color: #d48b39;
		border-radius: 64rpx;
	}

	.footer_di {
		width: 100%;
		padding: 30rpx 30rpx 30rpx 30rpx;
		background-color: #ffff;
		position: fixed;
		bottom: 0rpx;
		box-sizing: border-box;
	}
</style>